# encoding: utf-8
# @File  : test01_login_pass.py
# @Author: wu shaofan
# @Date  :  2024/04/17
# @Desc :  前台文web端登录页面，用户登录成功用例
import json
import allure
import pytest
import config
import conftest
from PO.page.page_login import PageLogin
from PO.page.page_user_info import PageUserinfo
from Utils.get_driver import GetDriver
from Utils.record_log import Log
from config import login_url


@allure.feature('1、登录模块')
class TestLogin:
    def setup_class(self):
        # 获取驱动对象
        self.driver = GetDriver().get_driver(login_url)
        # 异常截图
        conftest.driver = self.driver
        # 获取登录页面对象
        self.login = PageLogin(self.driver)
        # 获取个人中心页面对象
        self.userhome = PageUserinfo(self.driver)
        # 获取日志对象
        self.log = Log("登录成功用例").get_logger()

    def teardown_class(self):
        # 关闭驱动对象
        GetDriver().close_driver()
        Log("登录成功用例").write_empty_line()

    @allure.story('1、登录成功')
    def test_login01(self):
        with allure.step("测试步骤一：输入用户名"):
            self.login.page_input_username("18325530001")

        with allure.step("测试步骤二：输入密码"):
            self.login.page_input_password("wsf123456")

        with allure.step("测试步骤三：输入验证码"):
            self.login.page_input_verify_code("8888")

        with allure.step("测试步骤四：点击登录按钮"):
            self.login.page_click_login_btn()

        with allure.step("断言：登录成功后跳转到个人中心页面，获取用户名"):
            text = self.userhome.page_get_user_name()
            self.login.base_get_allure_image()

        assert text == "账户安全："

        data = {
            "用户信息": config.testdata,
            "断言": {
                "预期结果": "账户安全：",
                "实际结果": text}}
        self.log.info(f"测试数据：{data}")
        data = json.dumps(data, ensure_ascii=False, indent=4)
        allure.attach(data, "测试数据", allure.attachment_type.JSON)


if __name__ == '__main__':
    pytest.main()
